package com.yhyang.example.serviceprovider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class ServiceProviderApplication {

    private Logger logger = LoggerFactory.getLogger(ServiceProviderApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ServiceProviderApplication.class, args);
    }

    @Autowired
    private Environment environment;

    @GetMapping("/host")
    public String host() {
        return environment.getProperty("server.port");
    }


    @GetMapping("/hystrix")
    public String hystrix() throws InterruptedException {
//        int sleepTime = new Random().nextInt(2100);
//        logger.info("sleepTime:{}", sleepTime);
//        Thread.sleep(sleepTime);
        return environment.getProperty("server.port");
    }

}
